Back to Course

Lecture 1

Why OOP? & Introduction to Java

Welcome to Semester 4!

A very important subject — Object-Oriented Programming with Java

Today's Focus

  • Not about Java syntax
  • Not about memorizing definitions
  • About how programmers think when software becomes large

Interactive Question

How many of you enjoyed programming in C?

How many felt programs became confusing after 300-400 lines?

Setting the Context

From C Programming to OOP

What You Already Know

  • Variables, loops, arrays
  • Structures and functions
  • Procedural thinking

Traditional C Programming Approach

"Write a function, pass data to it, get the result."

This Works Perfectly For:

  • ✅ Small programs
  • ✅ Single-file projects
  • ✅ Academic exercises

Critical Thinking

Can we build a banking system, hospital system, or university management system using only functions and global data?

Yes, easily
No, never
Technically yes, practically no

Problems with Procedural Programming

When Complexity Strikes

University Management System Example

Imagine managing:

  • 👥 Students
  • 👨‍🏫 Faculty
  • 📚 Courses
  • 📊 Attendance
  • 📝 Exams
  • 🎯 Results

Critical Questions

Student data is used in how many functions?

What happens if the student structure changes?

What happens with multiple programmers?

In Procedural Programming:

  • ❌ Data is often exposed
  • ❌ Any function can modify it
  • ❌ Debugging becomes painful
  • ❌ Maintenance becomes risky
Key Point: Procedural programming focuses on "what to do next"
Real-world systems focus on "who is responsible"

Why Object-Oriented Programming?

Managing Complexity

Clear Statement

OOP was not created to replace C.

It was created to manage complexity.

In the Real World:

  • You don't think in functions
  • You think in objects

Examples of Objects:

👨‍🎓 Student

Has properties: name, age, roll number

Can perform actions: study, attend exam

👨‍🏫 Teacher

Has properties: name, subject, experience

Can perform actions: teach, grade papers

📚 Course

Has properties: title, credits, duration

Can perform actions: enroll students, generate results

What is Object-Oriented Programming?

A Programming Paradigm

Definition

OOP is a programming paradigm where software is designed using objects that represent real-world entities.

Mapping Real World to OOP

Real World OOP Concept
Student Class
Name, age, roll number Data members
Study(), attendExam() Methods

🔑 Key Idea

In OOP, data and behavior live together.

This is the biggest shift from C.

Core Concept: Data + Behavior Together

The Fundamental Shift

In C Programming:

struct Student { char name[50]; int age; }; void displayStudent(struct Student s) { printf("%s %d", s.name, s.age); }

In OOP (Java):

class Student { String name; int age; void display() { System.out.println(name + " " + age); } }

Why This Wrapping is Intentional:

  • 🔒 Data should not be freely accessible
  • ✅ Only valid actions should modify data
  • 🛡️ Improves safety and design

Four Pillars of OOP

The Foundation of Object-Oriented Design

Don't Panic!

Today, understand ideas, not definitions.

1️⃣ Encapsulation

What it means: Wrapping data and methods together, protecting data from misuse

Example: Bank account - you cannot directly change balance, must use deposit() or withdraw()

2️⃣ Abstraction

What it means: Showing what an object does, hiding how it does it

Example: ATM machine - you press buttons, don't see internal logic

3️⃣ Inheritance

What it means: Reusing existing code, creating new classes from old ones

Example: Person → Student → BTechStudent

4️⃣ Polymorphism

What it means: One interface, multiple behaviors

Example: draw() for circle vs draw() for rectangle - same call, different result

Transition to Java

From Concept to Implementation

🔍 Important Clarification

OOP is a concept.

Java is a tool to implement that concept.

Why Java?

  • ✨ Simple syntax compared to C++
  • 🚫 No pointer confusion
  • 🗑️ Automatic memory management
  • 🌐 Platform independent
  • 🏭 Huge industry usage
Key Point: Java forces you to think in objects, not shortcuts.

Did You Know?

Java was originally called "Oak" and was developed for interactive television!

Java Philosophy

Write Once, Run Anywhere

🌍 "Write Once, Run Anywhere"

Java code runs on Windows, Linux, macOS, and more!

How is this possible?

Because of JVM – Java Virtual Machine

The Magic of JVM:

  • Java doesn't run directly on hardware
  • It runs on JVM
  • JVM is platform-specific
  • This makes Java platform-independent

Technical Insight

Your Java code → Bytecode → JVM → Machine Code

First Look at Java Code

Putting Theory into Practice

Simple Java Example:

class Student { String name; int age; void display() { System.out.println(name + " " + age); } }

Let's Analyze:

  • What is this Student? → Class
  • What are name and age? → Data
  • What is display()? → Behavior

Object Creation:

Student s1 = new Student();

🎯 Key Concept

One class → many objects

Like one blueprint → many buildings

Course Roadmap

What We'll Cover This Semester

Our Journey:

  • 🏁 Start with OOP fundamentals
  • 🔗 Move to inheritance and interfaces
  • ⚡ Learn exception handling and multithreading
  • 🖥️ Build GUI applications
  • 🗄️ Connect Java with databases
  • 🏆 Complete a capstone project

🎓 Important Note

This is not a memorization subject.

This is a thinking subject.

Success Strategy

Focus on understanding concepts, not just syntax!

Expectations

What I Expect From You

From You, I Expect:

  • 📅 Regular practice
  • 💻 Writing small programs
  • ❓ Asking questions
  • 🧠 Thinking in objects

From Me, You'll Get:

  • 📚 Clear explanations
  • 🌍 Real-world examples
  • 🏭 Industry-oriented approach

Interactive Poll

What excites you most about OOP?

Building real applications
Better code organization
Industry relevance
All of the above!

Closing Thoughts

The Mindset Shift

💭 Final Thought

"Good programmers write code.

Great programmers design systems."

From Today Onwards:

  • 🚫 Stop thinking like C programmers
  • ✅ Start thinking like software designers

Homework / Reflection:

Before next class, pick any real-world system and identify:
  • Objects
  • Data
  • Actions

🎯 Thank You!

We'll continue in the next lecture with Classes and Objects in detail.